define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'exam.grade_log/index' + location.search,
                    add_url: 'exam.grade_log/add',
                    edit_url: 'exam.grade_log/edit',
                    // del_url: 'exam.grade_log/del',
                    multi_url: 'exam.grade_log/multi',
                    import_url: 'exam.grade_log/import',
                    table: 'exam_grade_log',
                }
            });

            var table = $("#table");

            //当内容渲染完成给编辑按钮添加`data-area`属性，点击列表编辑按钮时全屏
            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".btn-detail").data("area", ["90%", "90%"]);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {field: 'id', title: __('Id')},
                        {field: 'user_name', title: __('User_name'), operate: 'LIKE'},
                        {field: 'type_name', title: __('type_name'), operate: 'LIKE',searchList: {"初考":__('初考'),"复考":__('复考')}},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'accuracy_score', title: __('Accuracy_score'), operate:'BETWEEN'},
                        // {field: 'fluency_score', title: __('Fluency_score'), operate:'BETWEEN'},
                        // {field: 'standard_score', title: __('Standard_score'), operate:'BETWEEN'},
                        // {field: 'total_score', title: __('Total_score'), operate:'BETWEEN'},
                        // {field: 'markedRedNum', title: __('Markedrednum')},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('Detail'),
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'exam/grade/index'
                                },
                                {
                                    name: 'edit',
                                    icon: 'fa fa-pencil',
                                    classname: 'btn btn-xs btn-success btn-editone',
                                    url: 'exam/grade_log/edit'
                                },
                                {
                                    name: 'execute',
                                    title: __('专家点评'),
                                    text: __('专家点评'),
                                    visible:function (row) {
                                        if(row['status'] == "1"){
                                            return true;
                                        }else{
                                            return false;
                                        }
                                    },
                                    url: 'exam/grade_log/comment',
                                    icon: 'fa',
                                    classname: 'btn btn-danger btn-xs btn-execute btn-dialog',
                                    success: function (data, ret) {
                                        console.log(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        Layer.alert(ret.msg + ",返回数据：" + JSON.stringify(data));
                                        //如果需要阻止成功提示，则必须使用return false;
                                        //return false;
                                    },
                                },
                                
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
